package com.smart.controller;

import com.smart.pojo.ConceptualProduct;
import com.smart.pojo.ResultBean;
import com.smart.req.ConceptualCompleteData;
import com.smart.service.ConceptualProcessService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("conceptualProcess")
public class ConceptualProcessController {
    @Autowired
    private ConceptualProcessService conceptualProcessService;

    /**
     * 开启请假流程实例
     */
    @PostMapping("startProcess")
    @RequiresPermissions({"conceptual:save"})
    public ResultBean startConceptualProcess(@RequestBody ConceptualProduct conceptualProduct){
        System.out.println("研发方案申请详情：" + conceptualProduct);
        boolean rs = conceptualProcessService.startConceptualProcess(conceptualProduct);
        return rs ? ResultBean.success() : ResultBean.error();
    }

    /**
     * 请假单流程推进
     */
    @PostMapping("complete")
    public ResultBean complete(@RequestBody ConceptualCompleteData conceptualCompleteData){
        System.out.println("研发流程推进信息：" + conceptualCompleteData);
        conceptualProcessService.complete(conceptualCompleteData);
        return ResultBean.success();
    }

    /**
     * 研发部门查看研发方案
     */
    @GetMapping("getDevelopedTask/{userId}")
    public ResultBean getDevelopedTask(@PathVariable("userId") Long userId){
        System.out.println("获取待研发方案的用户的ID：" + userId);
        Map<String,Object> map = conceptualProcessService.getDevelopedTask(userId);
        return ResultBean.success(map);
    }
}
